<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-lx-cascades"></i> 大师管理</el-breadcrumb-item>
                <el-breadcrumb-item>待审核大师列表</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <!-- <el-button type="primary" icon="el-icon-delete" class="handle-del mr10" @click="delAll">批量</el-button> -->
                <el-input v-model="select_word" placeholder="筛选关键词" class="handle-input mr10" @change="refresh"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="search">搜索</el-button>
            </div>
            <el-table :data="toMasterData" border class="table" ref="multipleTable" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column type="index" width="80" align="center" label="序号" sortable="true"></el-table-column>
                <el-table-column label="头像" width="90">
                    <template slot-scope="scope">
                        <el-image style="width: 60px; height: 60px" fit="cover"
                            :src="`http://localhost/fitness/public/static/img/`+scope.row.avatar"
                            @click="handlePictureCardPreview(scope.row.avatar)">
                            <div slot="error" class="image-slot">
                                <i class="el-icon-picture-outline"></i>
                            </div>
                        </el-image>
                    </template>
                </el-table-column>
                <el-table-column prop="coachname" label="教练姓名" width="120">
                </el-table-column>
                <el-table-column prop="clubname" label="所属俱乐部" width="180">
                </el-table-column>
                <el-table-column label="性别" width="120">
                    <template slot-scope="scope">
                        {{scope.row.sex===1?'男':'女'}}
                    </template>
                </el-table-column>
                <el-table-column prop="area" label="申请领域" width="auto">
                </el-table-column>
                <el-table-column prop="masterdate" label="申请日期" sortable width="200">
                </el-table-column>
                <el-table-column label="操作" width="200" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" icon="el-icon-delete" class="red" @click="handleReject(scope.row)">驳回</el-button>
                        <el-button type="text" icon="el-icon-circle-check" @click="handleAdd(scope.row)">同意</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
        <!-- 驳回提示框 -->
        <el-dialog title="提示" :visible.sync="rejectVisible" width="300px" center>
            <div class="del-dialog-cnt">驳回不可恢复，是否确定驳回？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="rejectVisible = false">取 消</el-button>
                <el-button type="primary" @click="confirmReject">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 同意提示框 -->
        <el-dialog title="提示" :visible.sync="addVisible" width="300px" center>
            <div class="del-dialog-cnt">确定同意？</div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addVisible = false">取 消</el-button>
                <el-button type="primary" @click="confirmAdd">确 定</el-button>
            </span>
        </el-dialog>

        <!-- 预览图弹出框 -->
        <el-dialog :visible.sync="dialogImgVisible" width="25%">
            <img width="100%" :src="dialogImageUrl" alt="">
        </el-dialog>
    </div>
</template>

<script>
    export default {
        name: 'basetable',
        data() {
            return {
                toMasterData: [],
                multipleSelection: [],
                select_word: '',
                is_search: false,
                addVisible: false,
                rejectVisible: false,
                dialogImgVisible: false,
                dialogImageUrl: '',
                rejectid: 0,
                addid: 0
            }
        },
        created() {
            this.getData();
        },
        methods: {
            getData() {
                this.$axios.get('/api/Coach/toMasterList').then(res => {
                    this.toMasterData = res.data;
                })
            },
            search() {
                setTimeout(() => {
                    this.toMasterData = this.toMasterData.filter((d) => {
                        if(d.coachname.indexOf(this.select_word) > -1){
                            return d;
                        }
                    })
                }, 500);
            },
            refresh(){
                this.getData();
            },
            handleSelectionChange(val) {
                this.multipleSelection = val;
            },
            handlePictureCardPreview(url) {
                this.dialogImageUrl =`http://localhost/fitness/public/static/img/`+url;
                this.dialogImgVisible = true;
            },
            handleReject(row){
                this.rejectVisible = true;
                this.rejectid = row.coachid;
            },
            handleAdd(row){
                this.addVisible = true;
                this.addid = row.coachid;
            },
            confirmReject(){
                this.rejectVisible = false;
                this.$axios.get('/api/Coach/rejectMaster',{
                    params: {
                        coachid: this.rejectid
                    }
                }).then(res => {
                    if(res.data===1){
                        this.$message({
                            showClose: true,
                            message: '驳回成功',
                            type: 'success'
                        });
                        this.getData();
                    }
                })
            },
            confirmAdd(){
                this.addVisible = false;
                this.$axios.get('/api/Coach/addMaster',{
                    params: {
                        coachid: this.addid
                    }
                }).then(res => {
                    if(res.data===1){
                        this.$message({
                            showClose: true,
                            message: '成功处理',
                            type: 'success'
                        });
                        this.getData();
                    }
                })         
            }
        }
    }

</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }
    .del-dialog-cnt{
        font-size: 16px;
        text-align: center
    }
    .table{
        width: 100%;
        font-size: 14px;
    }
    .red{
        color: #ff0000;
    }
    .mr10{
        margin-right: 10px;
    }
</style>
